import { MutationTree } from 'vuex'
import { AppState, DeviceType } from './state'
import { AppMutationTypes } from './mutation-types'
import { setSidebarStatus, setLanguage, setSize } from '@/utils/cookies'

//导出类型
export type Mutations<S = AppState> = {
  [AppMutationTypes.TOGGLE_SIDEBAR](state: S, isCollapse: boolean): void
  [AppMutationTypes.SET_LANGUAGE](state: S, language: string): void
}


//导出具体方法
export const mutations: MutationTree<AppState> & Mutations = {
  [AppMutationTypes.TOGGLE_SIDEBAR](state: AppState, isCollapse: boolean) {
    state.sidebar.isCollapse = isCollapse
  },

  [AppMutationTypes.SET_LANGUAGE](state: AppState, language: string) {
    state.language = language
    setLanguage(state.language)
  }
}
